import 'package:flutter/material.dart';
import 'package:flutter_framework/utils/logs.dart';
import 'package:flutter_framework/views/custom_provider/model/logo_model.dart';

import 'model/change_notifier_provider.dart';

class CustomProvider extends StatefulWidget {
  const CustomProvider({super.key});

  @override
  State<CustomProvider> createState() => _CustomProviderState();
}

class _CustomProviderState extends State<CustomProvider> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('自定义provider'),
      ),
      body: Center(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            LogoDemo(),
            LogoPannel(),
          ],
        ),
      ),
    );
  }
}

class LogoDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    LogoModel _model = context.watch<LogoModel>();
    logs('logo demo rebuild');

    // TODO: implement build
    return Card(
      child: Transform.flip(
        flipX: _model.flipX,
        flipY: _model.flipY,
        child: FlutterLogo(
          size: 100 + _model.size * 100,
        ),
      ),
    );
  }
}

class LogoPannel extends StatefulWidget {
  const LogoPannel({super.key});

  @override
  State<LogoPannel> createState() => _LogoPannelState();
}

class _LogoPannelState extends State<LogoPannel> {
  late final LogoModel _model = context.watch<LogoModel>();

  @override
  Widget build(BuildContext context) {
    logs('logo pannel rebuild');
    return Card(
      child: Column(
        children: [
          Row(
            children: [
              Expanded(
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Text('flip Y:'),
                    Switch(
                        value: _model.flipY,
                        onChanged: (bool v) {
                          _model.flipY = v;
                        })
                  ],
                ),
              ),
              Expanded(
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Text('flip X:'),
                    Switch(
                        value: _model.flipX,
                        onChanged: (bool v) {
                          _model.flipX = v;
                        })
                  ],
                ),
              ),
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text('size:'),
              Slider(
                  value: _model.size,
                  onChanged: (double v) {
                    _model.size = v;
                  })
            ],
          ),
        ],
      ),
    );
  }
}
